#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"


void STInit(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->capcity = 0;
	pst->top = 0;
}
void STDestroy(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->capcity = pst->top = 0;
}
void STPush(ST* pst, STDateType x)
{
	assert(pst);
	if (pst->capcity == pst->top)
	{
		int newcapacity = pst->capcity == 0 ? 4 : 2 * pst->capcity;
		int* tmp = (int*)realloc(pst->a, sizeof(int) * newcapacity);
		if (tmp == NULL)
		{
			perror("realloc fail");
		}
		pst->a = tmp;
		tmp = NULL;
		pst->capcity = newcapacity;
	}
	pst->a[pst->top++] = x;
}
void STPop(ST* pst)
{
	assert(pst);
	assert(pst->top>=0);
	pst->top--;
}
STDateType STTop(ST* pst)
{
	assert(pst);
	assert(pst >= 0);
	return pst->a[pst->top-1];
}
int STSize(ST* pst)
{
	assert(pst);
	return pst->top;
}
bool STEmpty(ST* pst)
{
	assert(pst);
	return pst->top == 0;
}